package output;

import instance.Instance;
import instance.InstanceEj1;
import instance.InstanceEj2;

import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

public class Problem1Output implements Output{
	private static String outputFile;

	public Problem1Output(String nombArch){
		
	  outputFile = nombArch;
	}
	
	public void writeTestRend(LinkedList<String> strings_salida) throws Exception {
		/*||CUIDADO||:Usar despues de generar el tipo Problem1Output con el constructor que cambia el outputfile*/
		BufferedWriter bw = new BufferedWriter(new PrintWriter( Problem1Output.outputFile) );
		
		Iterator<String> it_res = strings_salida.iterator();
		while(it_res.hasNext()){
			String st = it_res.next();
			bw.write(st);
			if(it_res.hasNext()) bw.newLine();
		}
		bw.close();
	}
	
	@Override
	public void writeFile(String soluciones) throws Exception {
		
		BufferedWriter bw = new BufferedWriter(new PrintWriter(
				Problem1Output.outputFile));

		bw.write(soluciones);
        bw.newLine();
        bw.close();
	}
	public void escribirSolucion(LinkedList<Integer> soluciones) throws Exception {
		
		BufferedWriter bw = new BufferedWriter(new PrintWriter(Problem1Output.outputFile));
		
		Iterator<Integer> it_res = soluciones.iterator();
		while(it_res.hasNext()){
			String st = it_res.next().toString();
			bw.write(st);
			if(it_res.hasNext()) bw.newLine();
		}
		bw.close();
	}
	
	public void writeInstance(LinkedList<InstanceEj1> lista_insts) throws Exception {
		/*||CUIDADO||:Usar despues de generar el tipo Problem1Output con el constructor que cambia el outputfile*/
		BufferedWriter bw = new BufferedWriter(new PrintWriter( Problem1Output.outputFile) );
		
		Iterator<InstanceEj1> it = lista_insts.iterator();
		while(it.hasNext()){
			InstanceEj1 inst = it.next();
			
			int [] arr = inst.getInstancia();
			
			for(int i=0; i<inst.getSize(); i++){
				bw.write(Integer.toString(arr[i]) +' ');
			}
			
			if(it.hasNext()) bw.newLine();
		}
		bw.close();
	}
}

